home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS24.ADF / Daisy / daisy.c < prev    next >
C/C++ Source or Header  |  1988-04-16  |  4KB  |  133 lines

  1. Message-ID: #5238.pnet02.amiga/usenet 4436 chars. (2 more)
  2. From: rap@dana.UUCP (Rob Peck)
  3. Newsgroups: comp.sys.amiga
  4. Subject: Re: Simple Example Desired
  5. Date: 16 Oct 87 17:31:07 GMT
  6. Organization: Dana Computer, Inc., Sunnyvale, CA
  7.  
  8. In article <224@shamash.UUCP>, jwabik@shamash.UUCP (Jeff Wabik) writes:
  9. > This has probably been asked before, but, could someone post (or mail) a
  10. > working example using the translator and narrator devices?  I've been 
  11. > scratching my head for a few days here, even examining such goodies as
  12. > speechtoy.c, but with no luck.  My environment is Manx 3.4 ..  
  13. >       -Jeff
  14.  
  15. I created this 99 line program in the hopes that it would be killer
  16. demo material.  It is too short, I believe, for the sources posting
  17. hopefully qualifying as message-only status for all purposes.  This
  18. is about as short and simple as you can get when dealing with the
  19. narrator and translator.  To simplify it further, you could also
  20. delete the creation of rn - the message block that reads the mouths.
  21.  
  22. I wanted to make the narrator sing.  It sorta does it, but the syllables
  23. are too far apart to have anyone say "yes, it really does sing".  Yet
  24. it does provide at least a jumping off point for folks to use
  25. (creation method: 1. open speechtoy.c source, 2. remove anything
  26. not strictly speech-related, 3. compile whats left.)  I was told by
  27. Mark Barton that I'd have to get deep into the Narrator device code
  28. in order to "really" do what I wanted, since it was not designed
  29. to sing in the first place.  You'll find that he was right.
  30.  
  31. The test phrase, by the way, folks said "if you are going to make
  32. it sing, surely you won't want to use 'Daisy, daisy....'"
  33. Well, they were wrong.
  34.  
  35. Hope it helps.                  Rob Peck        ...ihnp4!hplabs!dana!rap
  36.  
  37. --- cut here, might be Manx-compatible (cc +L ...; ln ... c32.lib, at least)
  38.  
  39. #include "exec/types.h"
  40. #include "exec/exec.h"
  41. #include "exec/nodes.h"
  42. #include "exec/lists.h"
  43. #include "exec/memory.h"
  44. #include "exec/interrupts.h"
  45. #include "exec/ports.h"
  46. #include "exec/libraries.h"
  47. #include "exec/io.h"
  48. #include "exec/tasks.h"
  49. #include "exec/execbase.h"
  50. #include "devices/narrator.h"
  51. #include "libraries/translator.h"
  52.  
  53. struct MsgPort *readPort=0;
  54. struct MsgPort *writePort=0;
  55.  
  56. extern struct MsgPort *CreatePort();
  57. extern struct IORequest *CreateExtIO();
  58.                   
  59. struct narrator_rb *wn=0;
  60. struct mouth_rb *rn=0;
  61.                            
  62. struct Library *TranslatorBase =0;
  63.     
  64. UBYTE *sampleInput;
  65. UBYTE outputString[500];
  66. SHORT rtnCode, readError, writeError, error;
  67.      
  68. UBYTE audChanMasks[4] = { 3,5,10,12 };
  69.                                                       
  70. extern struct Library *OpenLibrary();
  71. #define REVISION 1
  72. char *words[ ] = {
  73.                 "da","zee","da","zee","give","me",
  74.                 "your","an","sir","doooo" };
  75. long pitches[] = { 300, 285, 270, 250, 260, 270, 285, 270, 285, 230 };
  76.  
  77. main()
  78. {
  79.   long i;
  80.   TranslatorBase = OpenLibrary("translator.library",REVISION);
  81.   if(TranslatorBase == NULL) exit(20);
  82.  
  83.   writePort = CreatePort(0,0);
  84.   if(writePort == NULL) goto cleanup;
  85.                      
  86.   readPort = CreatePort(0,0);
  87.   if(readPort == NULL) goto cleanup;
  88.  
  89.   wn = (struct narrator_rb *)CreateExtIO(writePort,
  90.         sizeof(struct narrator_rb));
  91.  
  92.   rn = (struct mouth_rb *)CreateExtIO(readPort,
  93.         sizeof(struct mouth_rb));
  94.  
  95.   if(rn == NULL || wn == NULL) goto cleanup;
  96.  
  97.   wn->ch_masks = audChanMasks;
  98.   wn->nm_masks = 1;   /* restrict to one channel */
  99.   wn->message.io_Data    = (APTR)outputString;
  100.   wn->message.io_Length  = strlen(outputString);
  101.   wn->mouths = 0;             /* NO MOUTHS! Wont read em anyhow.*/
  102.   wn->message.io_Command = CMD_WRITE;
  103.  
  104.   error = OpenDevice("narrator.device",0,wn,0);
  105.   if(error != 0) goto cleanup;
  106.  
  107.   for(i=0; i<10; i++)
  108.   {
  109.   sampleinput = words[i];
  110.   rtnCode = Translate(sampleInput, 
  111.   strlen(sampleInput),outputString,500);
  112.                                
  113.   wn->pitch = pitches[i];
  114.   wn->mode  = 1;          /* ROBOTIC */
  115.                                                 
  116.   wn->message.io_Data    = (APTR)outputString;
  117.   wn->message.io_Length  = strlen(outputString);
  118.   wn->message.io_Command = CMD_WRITE;
  119.  
  120.   writeError = DoIO(wn);
  121.   }
  122. cleanup:
  123.   if(wn->message.io_Device) CloseDevice(wn);
  124.   if(wn) DeleteExtIO(wn);
  125.   if(rn) DeleteExtIO(rn);
  126.   if(TranslatorBase) CloseLibrary(TranslatorBase);
  127.   if(readPort) DeletePort(readPort);
  128.   if(writePort) DeletePort(writePort);
  129. }
  130.  
  131.  
  132.